package club.emergency.wechat.question_collection.operate.provider.impl;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.model.question_collection.QuestionCollection;
import club.emergency.wechat.persistence.question_collection.QuestionCollectionMapper;
import club.emergency.wechat.question_collection.operate.QuestionCollectionOperate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.question_collection.operate.provider.impl
 * Date: 2019/2/21
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@RestController
@Transactional(rollbackFor = Exception.class)
public class QuestionCollectionOperateImpl implements QuestionCollectionOperate {

    private QuestionCollectionMapper questionCollectionMapper;

    public QuestionCollectionOperateImpl(QuestionCollectionMapper questionCollectionMapper) {
        this.questionCollectionMapper = questionCollectionMapper;
    }

    @Override
    public String save(@RequestBody QuestionCollection questionCollection) {
        questionCollectionMapper.insert(questionCollection);
        return ResponseEntity.ok(StatusCode.DB_SAVE_OK, "新增试题收藏记录成功！", questionCollection.getId());
    }

    @Override
    public String remove(@RequestParam("staffId") Long staffId, @RequestParam("questionId") Long questionId) {
        questionCollectionMapper.remove(staffId, questionId);
        return ResponseEntity.ok(StatusCode.DB_REMOVE_ERROR, "删除试题收藏记录成功！");
    }

}
